using RealtimeCollabGame.Domain.ValueObjects;

namespace RealtimeCollabGame.Domain.ValueObjects;

public record GameResult(Guid GameId, List<PlayerScore> PlayerScores, DateTime? StartedAt, DateTime? EndedAt)
{
    public PlayerScore? Winner => PlayerScores.FirstOrDefault();
    
    public int TotalArea => PlayerScores.Sum(ps => ps.Area);
    
    public TimeSpan? Duration => StartedAt.HasValue && EndedAt.HasValue ? EndedAt.Value - StartedAt.Value : null;
    
    public void CalculatePercentages()
    {
        var totalArea = TotalArea;
        foreach (var score in PlayerScores)
        {
            score.CalculatePercentage(totalArea);
        }
    }
} 